package cn.itsource.ymcc.producer;

import cn.itsource.ymcc.constant.MediaConstants;
import cn.itsource.ymcc.domain.MediaFile;
import cn.itsource.ymcc.result.JsonResult;
import cn.itsource.ymcc.service.IMediaFileService;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.client.producer.SendStatus;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class MediaProducerImpl implements MediaProducer{
    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    @Override
    public JsonResult handleFile2m3u8(MediaFile mediaFile) {
        //发送消息
        SendResult sendResult = rocketMQTemplate
                .syncSend(MediaConstants.TOPIC_COURSE_VIDEO_PUSH_TO_SRS + ":" + MediaConstants.TAGS_COURSE_VIDEO_PUSH_TO_SRS,
                MessageBuilder.withPayload(JSON.toJSONString(mediaFile)).build());
        return sendResult.getSendStatus()== SendStatus.SEND_OK?JsonResult.success():JsonResult.error("视频上传失败");
    }
}
